(function(cjs, as){
	(as.TransformBox=function(x,y,w,h){
		this.Container_constructor();
		x=x||0,y=y||0,w=w||100,h=h||100;
		var self=this;
		
		this._center=false;
		this._r=5;
		this._top=x;
		this._left=y;
		this._right=w+x;
		this._bottom=h+y;
		
		var shape0=new cjs.Shape();
		this.addChild(shape0);
		
		//top
		var control_top=new cjs.Shape();
		control_top.name="top";
		control_top.graphics.setStrokeStyle(1,"round").beginStroke("#000");
		control_top.graphics.beginFill("#fff").dc(0, 0, this._r);
		this.addChild(control_top);
		//left
		var control_left=new cjs.Shape();
		control_left.name="left";
		control_left.graphics.setStrokeStyle(1,"round").beginStroke("#000");
		control_left.graphics.beginFill("#fff").dc(0, 0, this._r);
		this.addChild(control_left);
		//right
		var control_right=new cjs.Shape();
		control_right.name="right";
		control_right.graphics.setStrokeStyle(1,"round").beginStroke("#000");
		control_right.graphics.beginFill("#fff").dc(0, 0, this._r);
		this.addChild(control_right);
		//bottom
		var control_bottom=new cjs.Shape();
		control_bottom.name="bottom";
		control_bottom.graphics.setStrokeStyle(1,"round").beginStroke("#000");
		control_bottom.graphics.beginFill("#fff").dc(0, 0, this._r);
		this.addChild(control_bottom);
		//
		this.reset=function(){
			this._width=this._right-this._left;
			this._height=this._bottom-this._top;
			//绘制虚线框
			shape0.graphics.clear();
			shape0.graphics.setStrokeStyle(1,"round").setStrokeDash([5, 5], 0).beginStroke("#000");
			shape0.graphics.drawRect(this._left, this._top, this._width,this._height);
			//top
			control_top.setTransform(this._width/2+this._left,this._top);
			control_left.setTransform(this._left,this._height/2+this._top);
			control_right.setTransform(this._right,this._height/2+this._top);
			control_bottom.setTransform(this._width/2+this._left,this._bottom);
		}
		this.reset();
		//
		control_top.on('mouseover',function(){
			control_top.cursor="n-resize";
		},null,false);
		control_left.on('mouseover',function(){
			control_left.cursor="w-resize";
		},null,false);
		control_right.on('mouseover',function(){
			control_right.cursor="e-resize";
		},null,false);
		control_bottom.on('mouseover',function(){
			control_bottom.cursor="s-resize";
		},null,false);
		//
		var start_x,start_y,current_control="",temp_t,temp_l,temp_r,temp_b;
		this.on('mousedown',function(e){
			//console.log(e.target.name);
			start_x=e.localX;
			start_y=e.localY;
			temp_t=this._top;
			temp_l=this._left;
			temp_r=this._right;
			temp_b=this._bottom;
			switch(e.target.name){
				case "top":
				current_control="top";
				break;
				case "left":
				current_control="left";
				break;
				case "right":
				current_control="right";
				break;
				case "bottom":
				current_control="bottom";
				break;
				default:
				current_control="";
				break;
			}
		},null,false);
		//
		this.on('pressmove',function(e){
			//console.log(e.localX,e.localY);
			var d;
			switch(current_control){
				case "top":
				d=e.localY-start_y;
				self._top=temp_t+d;
				if(self._center)self._bottom=temp_b-d;
				self.reset();
				dispatchEvent('vertical');
				break;
				case "left":
				d=e.localX-start_x;
				self._left=temp_l+d;
				if(self._center)self._right=temp_r-d;
				self.reset();
				dispatchEvent('horizontal');
				break;
				case "right":
				d=e.localX-start_x;
				self._right=temp_r+d;
				if(self._center)self._left=temp_l-d;
				self.reset();
				dispatchEvent('horizontal');
				break;
				case "bottom":
				d=e.localY-start_y;
				self._bottom=temp_b+d;
				if(self._center)self._top=temp_t-d;
				self.reset();
				dispatchEvent('vertical');
				break;
			}
		},null,false);
		//
		function dispatchEvent(direct){
			var evt=new cjs.Event('change');
			self._width=self._right-self._left;
			self._height=self._bottom-self._top;
			evt.data={x:self._left,y:self._top,width:self._width,height:self._height,direction:direct};
			self.dispatchEvent(evt);
		}
	});
	var p=cjs.extend(as.TransformBox,cjs.Container);
	//axis
	p._get_axis=function(){
		return this._center;
	};
	p._set_axis=function(value){
		if(typeof(value)=='boolean'){
			this._center=value;
		}
	};
	try{
		Object.defineProperties(p,{
			axis:{get:p._get_axis,set:p._set_axis}
		});
	} catch (e) {}
	//width
	p._get_width=function(){
		return this._width;
	};
	p._set_width=function(value){
		this._left=-value/2;
		this._right=value/2;
		this.reset();
	};
	try{
		Object.defineProperties(p,{
			width:{get:p._get_width,set:p._set_width}
		});
	} catch (e) {}
	//height
	p._get_height=function(){
		return this._height;
	};
	p._set_height=function(value){
		this._top=-value/2;
		this._bottom=value/2;
		this.reset();
	};
	try{
		Object.defineProperties(p,{
			height:{get:p._get_height,set:p._set_height}
		});
	} catch (e) {}
	as.TransformBox = cjs.promote(as.TransformBox, "Container");
})(createjs = createjs||{}, ascainiao = ascainiao||{});
var createjs, ascainiao;